﻿Imports DTO
Imports System.Data.OleDb
Public Class KhamBenhDAO
    'Public Shared Sub Them(ByVal hsDto As KhamBenhDTO)
    '    Dim cn As OleDbConnection
    '    'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
    '    cn = Data_Provider.ConnecDTB()
    '    'B3: Tao chuoi strSQL thao tac CSDL
    '    Dim strSQL As String
    '    strSQL = "Insert into HocSinh(Ten, NgaySinh, DiaChi, Toan, Ly, Hoa, DTB, MaLop) values (?, ?, ?, ?, ?, ?, ?, ?)"

    '    'B4: Thuc thi chuoi strSQL
    '    Dim cmd As New OleDbCommand(strSQL, cn)

    '    cmd.Parameters.Add("@HoTen", OleDbType.WChar)
    '    cmd.Parameters.Add("@NgaySinh", OleDbType.Date)
    '    cmd.Parameters.Add("@DiaChi", OleDbType.WChar)
    '    cmd.Parameters.Add("@GioiTinh", OleDbType.WChar)
    '    cmd.Parameters.Add("@NgayKham", OleDbType.Date)


    '    cmd.Parameters("@HoTen").Value = hsDto.HoTen
    '    cmd.Parameters("@NgaySinh").Value = hsDto.NamSinh
    '    cmd.Parameters("@DiaChi").Value = hsDto.DiaChi
    '    cmd.Parameters("@GioiTinh").Value = hsDto.GioiTinh
    '    cmd.Parameters("@NgayKham").Value = hsDto.NgayKham

    '    cmd.ExecuteNonQuery()

    '    strSQL = "Select @@IDENTITY"
    '    cmd = New OleDbCommand(strSQL, cn)
    '    hsDto.MaBenhNhan = cmd.ExecuteScalar()
    '    'B5: Dong ket noi CSDL
    '    cn.Close()
    'End Sub
    Public Function Themphieukhambenh(ByVal cnDTO As DTO.KhamBenhDTO) As Integer
        Dim sql As String = " insert into KHAMBENH(HoTen,DiaChi,GioiTinh,NamSinh,NgayKham) values(@HoTen,@DiaChi,@GioiTinh,@NamSinh,@NgayKham)"
        Dim connec As OleDbConnection = DAO.Data_Provider.ConnecDTB()
        Dim command As New OleDbCommand(sql, connec)
        Dim para As New OleDb.OleDbParameter
        para = command.Parameters.Add("@HoTen", OleDbType.VarChar)
        para.Value = cnDTO.HoTen

        para = command.Parameters.Add("@DiaChi", OleDbType.VarChar)
        para.Value = cnDTO.DiaChi

        para = command.Parameters.Add("@GioiTinh", OleDbType.VarChar)
        para.Value = cnDTO.GioiTinh

        para = command.Parameters.Add("@NamSinh", OleDbType.Date)
        para.Value = cnDTO.NamSinh

        para = command.Parameters.Add("@NgayKham", OleDbType.Date)
        para.Value = cnDTO.NgayKham
        command.ExecuteNonQuery()
        Dim i As Integer = command.ExecuteNonQuery()
        connec.Close()
        If i >= 0 Then
            Return 1
        Else
            Return 0
        End If
    End Function
End Class
